// JavaScript Document
var jc={};
jc.tools={};
jc.ui={};
jc.app={};
//getStyle
jc.tools.getStyle=function(obj, attr){
	if(obj.currentStyle){
		return obj.currentStyle[attr];
	}else{
		return getComputedStyle(obj, false)[attr];
	}
}
//getByClass
jc.tools.getByClass=function(oParent, sClass){
	var aEle=oParent.getElementsByTagName('*');
	var aTmp=[];
	var re=new RegExp('\\b'+sClass+'\\b', 'i');
	var i=0;
	for(i=0;i<aEle.length;i++){
		if(re.test(aEle[i].className)){
			aTmp.push(aEle[i]);
		}
	}
	return aTmp;
}
//运动框架
jc.ui.startMove=function(obj,json,fn){
	clearInterval(obj.timer);
	obj.timer=setInterval(function (){
		var bStop=true;//这一次运动就结束了——所有的值都到达了
		for(var attr in json){
			//1.取当前的值
			var iCur=0;
			if(attr=='opacity'){
				iCur=Math.round(parseFloat(jc.tools.getStyle(obj, attr))*100);
			}else{
				iCur=parseInt(jc.tools.getStyle(obj, attr));
			}
			//2.算速度
			var iSpeed=(json[attr]-iCur)/8;
			iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
			//3.检测停止
			if(iCur!=json[attr]){
				bStop=false;
			}
			if(attr=='opacity'){
				obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')';
				obj.style.opacity=(iCur+iSpeed)/100;
			}else{
				obj.style[attr]=iCur+iSpeed+'px';
			}
			//document.title=iCur+iSpeed; //测试
		}
		if(bStop){
			clearInterval(obj.timer);
			if(fn){
				fn();
			}
		}
	},15)
}
window.onload=function(){
	//jc.app.writeAccount();
}
jc.app.writeAccount=function(){
	var obj=jc.tools.getByClass(document,'list')[0];
	var LOGO=jc.tools.getByClass(document,'LOGO')[0];
	var form=jc.tools.getByClass(document,'form')[0];
	var Reset=document.getElementById('reset');
	var Submit=document.getElementById('submit');
	var Prompt=jc.tools.getByClass(document,'prompt')[0];
	var PromptText=Prompt.getElementsByTagName('span')[0];
	form.style.left=form.offsetLeft-120+'px';
	LOGO.style.top='-580px';
	form.style.bottom='-580px';
	LOGO.style.opacity=form.style.opacity='0';
	jc.ui.startMove(LOGO,{top:Math.round((document.body.clientHeight/2)-(LOGO.offsetHeight/2)),opacity:100});
	jc.ui.startMove(form,{bottom:(document.body.clientHeight/2)-(form.offsetHeight/2),opacity:100});
	var writeAccountInput=obj.getElementsByTagName('input');
	for(var i=0;i<writeAccountInput.length;i++){
		writeAccountInput[i].index=i;
		jc.ui.writeAccountText(writeAccountInput[i],writeAccountInput[i].value);
		Submit.onclick=function(){
			var Write=[writeAccountInput[0].value,writeAccountInput[1].value,writeAccountInput[2].value];
			var Account=['123','123','123'];
			for(var i=0;i<writeAccountInput.length;i++){
				if(writeAccountInput[0].value==''){
					jc.ui.shake(form);
					PromptText.innerHTML='用户名不能为空';
					return false;
				}else if(writeAccountInput[1].value==''){
					jc.ui.shake(form);
					PromptText.innerHTML='密码不能为空';
					return false;
				}else if(writeAccountInput[2].value==''){
					jc.ui.shake(form);
					PromptText.innerHTML='验证码不能为空';
					return false;
				}else if(Write.sort().toString()!=Account.sort().toString()){
					jc.ui.shake(form);
					PromptText.innerHTML='用户名或密码错误请重新输入!';
					return false;
				}else{
					return true;
				}
			}
		}
	}
}
jc.ui.shake=function(obj){
	var Prompt=jc.tools.getByClass(document,'prompt')[0];
	Prompt.style.display='block';
	var oLeftSize=obj.offsetLeft;
	setTimeout(function(){obj.style.left=oLeftSize-30+'px'},50);
	setTimeout(function(){obj.style.left=oLeftSize+'px'},100);
	setTimeout(function(){obj.style.left=oLeftSize+30+'px'},150);
	setTimeout(function(){obj.style.left=oLeftSize+'px'},200);
	setTimeout(function(){obj.style.left=oLeftSize-10+'px'},250);
	setTimeout(function(){obj.style.left=oLeftSize+'px'},300);
	setTimeout(function(){obj.style.left=oLeftSize+10+'px'},350);
	setTimeout(function(){obj.style.left=oLeftSize+'px'},400);
}
jc.ui.writeAccountText=function(obj,value){
	var Prompt=jc.tools.getByClass(document,'prompt')[0];
	var captcha=jc.tools.getByClass(document,'captcha')[0];
	obj.onfocus=function(){
		obj.className=this.className+' curr';
		Prompt.style.display='none';
		if(obj.value==''){
			this.style.color='#000';
		}
		if(obj.index==1){
			this.type='password';
		}
		if(obj.index==2){
			captcha.style.display='block';
			jc.ui.startMove(captcha,{opacity:100});
		}
	}
	obj.onblur=function(){
		var _className=this.className;
		this.className=_className.replace(/curr/,'');
		if(obj.value==''){
			obj.style.color='#ababab';
			if(obj.index==1){
				this.type='text';
			}
		}
		if(obj.index==2){
			_this=this;
			captcha.onclick=function(){
				_this.focus();
			}
			jc.ui.startMove(captcha,{opacity:0},function(){
				captcha.style.display='none';
			})
		}
	}
}